Skip to content

获取自更新进度 - SoftUpdateGetProgress

函数简介

获取当前进程内自更新进度快照(下载/准备阶段)。Updater 已拉起且宿主退出后,请改读 SoftUpdateGetLastStatus

返回数据格式:

json
{
  "Code": 1,
  "Phase": "downloading",
  "Percent": 45,
  "BytesCurrent": 1000000,
  "BytesTotal": 2000000,
  "Message": "",
  "IsFinished": false,
  "IsFailed": false
}
字段名类型说明
Code整数1 表示接口调用成功。
Phase字符串idle / checking / downloading / verifying / extracting_updater / launching / done / failed
Percent整数0–100。
BytesCurrent整数已下载字节数。
BytesTotal整数总字节数;未知时为 0。
Message字符串阶段说明。
IsFinished布尔是否已结束(成功或失败)。
IsFailed布尔是否失败。

接口名称

SoftUpdateGetProgress

DLL调用

long SoftUpdateGetProgress();

参数说明

无参数。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();
// progress.Percent / progress.Phase / progress.IsFinished
csharp
using OLAPlug;

var ola = new OLAPlugServer();
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
json_result = ola.SoftUpdateGetProgress()
# Python SDK 返回 JSON 字符串,需自行解析
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.OlaSoftUpdateProgressReturn;

OLAPlugServer ola = new OLAPlugServer();
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
progress := ola.SoftUpdateGetProgress()
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let progress = ola.soft_update_get_progress();
cpp
var ola = com("OlaPlug.OlaSoft")
var progress = ola.SoftUpdateGetProgress()
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
Set progress = ola.SoftUpdateGetProgress()
text
.局部变量 ola, OLAPlug
.局部变量 progress, OlaSoftUpdateProgressReturn
ola.创建 ()
progress = ola.SoftUpdateGetProgress()
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var json = ola.SoftUpdateGetProgress();
// Aardio SDK 返回 JSON 字符串,需自行解析
text
变量 ola <类型 = OLAPlugServer>
变量 progress <类型 = OlaSoftUpdateProgressReturn>
ola = 新建 OLAPlugServer
progress = ola.SoftUpdateGetProgress()
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
OlaSoftUpdateProgressReturn progress = ola.SoftUpdateGetProgress();

原生 DLL 调用

cpp
long ptr = SoftUpdateGetProgress();
if (ptr != 0) {
    char buffer[2048] = {0};
    GetStringFromPtr(ptr, buffer, sizeof(buffer));
    FreeStringPtr(ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long SoftUpdateGetProgress();

long ptr = SoftUpdateGetProgress();
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string result = sb.ToString();
}
python
from ctypes import CDLL, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ptr = ola.SoftUpdateGetProgress()
if ptr:
    buf = create_string_buffer(2048)
    ola.GetStringFromPtr(ptr, buf, 2048)
    ola.FreeStringPtr(ptr)
    result = buf.value.decode("utf-8")

返回值

调用方式返回值说明
SDKOlaSoftUpdateProgressReturn结构化进度对象
原生 DLL非 0成功,返回 JSON 字符串指针
原生 DLL0失败

注意事项

项目说明
作用域仅反映当前进程内下载/准备阶段;宿主退出后请用 SoftUpdateGetLastStatus
UI默认可静默;需要进度条时由宿主轮询本接口自行绘制。
释放内存原生返回指针需 FreeStringPtr